package common;

import java.awt.Container;

import javax.swing.JFrame;

import org.jfree.chart.ChartPanel;
import org.jfree.chart.JFreeChart;
import org.jfree.chart.axis.NumberAxis;
import org.jfree.chart.plot.XYPlot;
import org.jfree.chart.renderer.xy.XYBlockRenderer;
import org.jfree.data.xy.DefaultXYZDataset;
import java.awt.GridLayout;

public class JFreeChartHeatmap {

	JFrame frame;

	/**
	 * Create the application.
	 */
	public JFreeChartHeatmap() {
		initialize();
	}

	/**
	 * Initialize the contents of the frame.
	 */
	private void initialize() {
		frame = new JFrame();
		frame.setBounds(100, 100, 450, 300);
		frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		frame.getContentPane().setLayout(new GridLayout(1, 1, 0, 0));
	}
	
	public void showHeatmap(double[][] map, double[] scaleK0, double[] scaleRT){
		
		
		double[][] jfcFormat = JfcHeatTools.convertMatrixToJfcFormat(map, scaleK0, scaleRT, 0);
		double blockWidth =  scaleK0[scaleK0.length - 1] /  scaleK0.length;
		double blockHeight = scaleRT[scaleRT.length - 1] / (scaleRT.length);
		
		
		DefaultXYZDataset imsdds = new DefaultXYZDataset();
		imsdds.addSeries("", jfcFormat);
		WBRG_PaintScale paintScale = new WBRG_PaintScale(0, 40);
		XYBlockRenderer xybr = new XYBlockRenderer();
		xybr.setPaintScale(paintScale);
		xybr.setDataBoundsIncludesVisibleSeriesOnly(true);
		xybr.setBlockWidth(blockWidth);
		xybr.setBlockHeight(blockHeight);

		NumberAxis RTaxis = new NumberAxis("RT");
		NumberAxis K0axis = new NumberAxis("1/k0");
		K0axis.setAutoTickUnitSelection(true);
		XYPlot heatmapPlot = new XYPlot(imsdds, K0axis, RTaxis, xybr);
		JFreeChart chart = new JFreeChart(heatmapPlot);
		ChartPanel chartPanel = new ChartPanel(chart);
		frame.getContentPane().add(chartPanel);
		
		
	}

}
